<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Read Excel file</title>
</head>

<body>
<?php
	$filename=isset($_GET['SO_im'])?$_GET['SO_im']:" ";
	$arr_temp = explode("\\", $filename);
	$filename="C:/xampp/htdocs/00_JO/JOi/Import/".$arr_temp[2];
	
	$tab=isset($_GET['SO_tab'])?$_GET['SO_tab']:" ";
	$kytu='\r\n';
	include "DataProvider/DataProvider.php"; //Lớp kết nối DB
	
	/*--------------------------------------------
	/* Đọc và hiển thị file Excel
	/* Post by khoinguonit.com
	/*------------------------------------------*/
	
	//require_once 'controller/excel_reader_controller.php'; // Thư viện xử lý
	include_once('controller/JO_import_excel_controller.php');
	if($tab!='')
	{
		if($tab=='artist'){
		$sql="
LOAD DATA INFILE '$filename' IGNORE INTO TABLE jo.".$tab."
  FIELDS TERMINATED BY ',' ENCLOSED BY '\\\"'
  LINES TERMINATED BY '$kytu'
  IGNORE 1 LINES
  (@dt,`key_bugs`,`name`)
  SET `insert`=NOW(),
      `nation`      = 'KR'"; 
	   $result=JO_015_import($sql);
		}
		if($tab=='album'){
			$sql="
LOAD DATA INFILE '$filename' IGNORE INTO TABLE jo.".$tab."
  FIELDS TERMINATED BY ',' ENCLOSED BY '\\\"'
  LINES TERMINATED BY '$kytu'
  IGNORE 1 LINES
  (@dt,`artist`,@dt3,`key_bugs`,`subject`)
  SET `insert`=NOW(),
      `nation`      = 'KR'";
	   $result=JO_015_import($sql);
		}
		if($tab=='music'){
			$sql="
LOAD DATA INFILE '$filename' IGNORE INTO TABLE jo.".$tab."
  FIELDS TERMINATED BY ',' ENCLOSED BY '\\\"'
  LINES TERMINATED BY '$kytu'
  IGNORE 1 LINES
  (@STT,`key_bugs`,`artist`,@artist,`album`,@album,`subject`)
  SET `organization`= 6,
	  `insert`=NOW(),
      `nation`      = 'KR'";
	  $result=JO_015_import($sql);
		}
		if($tab=='rbt'){
			$sql="
LOAD DATA INFILE '$filename' IGNORE INTO TABLE jo.".$tab."
  FIELDS TERMINATED BY ',' ENCLOSED BY '\\\"'
  LINES TERMINATED BY '$kytu'
  IGNORE 1 LINES
  (@STT,@key_artist,@artist,@key_album,@album,`music`, `note`)
  SET 
	  `insert`=NOW()";
     
	  $result=JO_015_import($sql);
		}
	
	}
	
	if($result>0)
		echo '<div style="text-align:center; margin-top: 2%;;height:50px">Đã import thành công '. $result.' records</div>';
	

?>
</body>
</html>
